<template>
  <div class="login-panel">
    <h1>智能客服管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user-solid"></i> 账号登录</span>
        </template>
        <loginAccount ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-phone"></i> 游客登录</span>
        </template>
        <loginPhone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button @click="handleLoginClick" class="login-btn" type="primary"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import loginAccount from './login-account.vue'
import loginPhone from './login-phone.vue'

export default defineComponent({
  components: { loginAccount, loginPhone },
  setup() {
    // 1.定义属性
    const isKeepPassword = ref(true)
    // 拿到组件的类型
    const accountRef = ref<InstanceType<typeof loginAccount>>()
    const currentTab = ref('account')
    // 2.定义方法
    const handleLoginClick = () => {
      console.log('立即登录')
      if (currentTab.value === 'account') {
        accountRef.value?.loginAction(isKeepPassword.value)
      }
    }

    return { isKeepPassword, accountRef, currentTab, handleLoginClick }
  },
})
</script>

<style lang="less" scoped>
.login-panel {
  width: 320px;
}
.login-btn {
  width: 100%;
}
.account-control {
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}
</style>
